﻿using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace TechnicalIndicators.Points
{
	[DebuggerDisplay("X = {Start}, Max = {Maximum}, Min = {Minimum}, Open = {Open}, Close = {Close}")]
	public class Bar
	{
		#region Properties

		public decimal Maximum { get; set; }
		public decimal Minimum { get; set; }
		public decimal Open { get; set; }
		public decimal Close { get; set; }

		public DateTime Start { get; set; }
		public DateTime End { get; set; }

		public TimeSpan Duration
		{
			get
			{
				return this.End - this.Start;
			}
		}

		public List<decimal> Values { get; private set; }

		#endregion

		#region Public Methods

		public Bar(DateTime start, decimal value)
		{
			this.Values = new List<decimal>();

			this.Start = start;
			this.Open = value;
			this.Maximum = value;
			this.Minimum = value;

			this.AddValue(start, value);
		}

		public void AddValue(DateTime time, decimal value)
		{
			this.Values.Add(value);

			this.Close = value;
			this.End = time;
			this.Maximum = Math.Max(this.Maximum, value);
			this.Minimum = Math.Min(this.Minimum, value);
		}

		#endregion
	}
}
